
<%@ page import="fi.hell.lunchit.Restaurant" %>
<%@ page import="fi.hell.lunchit.User" %>
<%@ page import="fi.hell.lunchit.Round" %>

<g:set var="currentRound" value="${Round.currentRound()}" />
<g:set var="currentVote" value="${Round.currentVote(currentRound)}" />
<g:set var="loggedInUser" value="${User.getLoggedInUser()}" />
<g:set var="locale" value="${grailsApplication.config.locale}" />

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="layout" content="main" />
        <title>${restaurantInstance} - LunchIT</title>
        <g:set var="entityName" value="${message(code: 'restaurant.label', default: 'Restaurant')}" />
    </head>
    <body>
        <div class="nav">
            <span class="menuButton"><a class="home" href="${createLink(uri: '/')}"><g:message code="default.home.label"/></a></span>
            <span class="menuButton"><g:link class="list" action="list"><g:message code="default.list.label" args="[entityName]" /></g:link></span>
            <span class="menuButton"><g:link class="create" action="create"><g:message code="default.new.label" args="[entityName]" /></g:link></span>
        </div>
        
        <div class="showRestaurantPanel">
	        <g:if test="${restaurantInstance.homePage}">
	        <a href="${restaurantInstance.homePage}" target="_blank">
	        </g:if>
	    	<img class="panel" src="${createLink(controller:'image', action:'restaurantLogo', id:restaurantInstance.id)}" />
	    	<g:if test="${restaurantInstance.homePage}">
			</a>
	    	</g:if>
	    	
	    	<div class="buttons panel" style="margin-top:0">
				<g:form>
	                <g:hiddenField name="id" value="${restaurantInstance?.id}" />
	                <span class="button"><g:actionSubmit class="edit" action="edit" value="${message(code: 'default.button.edit.label', default: 'Edit')}" /></span>
	                <span class="button"><g:actionSubmit class="delete" action="delete" value="${message(code: 'default.button.delete.label', default: 'Delete')}" onclick="return confirm('${message(code: 'default.button.delete.confirm.message', default: 'Are you sure?')}');" /></span>
	            </g:form>
	        </div>
                
        	<g:render template="/panels" model="[loggedInUser:loggedInUser, currentRound:currentRound, currentVote:currentVote]" />
        </div>
        
        <div id="pageBody">
        	<h1>${restaurantInstance}</h1>
            
            <div class="list">
            
            	<table>
                    <tbody>
                    
                    	<g:if test="${restaurantInstance.homePage}">
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="restaurant.lunchMenu.label" default="Lunch menu" /></td>
                            <td valign="top" class="value"><a href="${restaurantInstance.homePage}" target="_blank">${restaurantInstance.homePage}</a></td>
                        </tr>
                        </g:if>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="restaurant.address.label" default="Address" /></td>
                            <td valign="top" class="value">${restaurantInstance.address}</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="restaurant.zip.label" default="Zip" /></td>
                            <td valign="top" class="value">${restaurantInstance.zip}</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="restaurant.city.label" default="City" /></td>
                            <td valign="top" class="value">${restaurantInstance.city}</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="restaurant.openingDays.label" default="Opening Days" /></td>
                            <td valign="top" class="value">
                            <g:each status="i" var="day" in="${restaurantInstance.openingDays}">
								<g:message code="day.${day}" /><g:if test="${i+1 < restaurantInstance.openingDays?.size()}">, </g:if>
							</g:each>
							</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="restaurant.tags.label" default="Tags" /></td>
                            <td valign="top" class="value">
                            <g:each status="i" var="tag" in="${restaurantInstance.tags}">
								<g:message code="restaurantTag.${tag}" /><g:if test="${i+1 < restaurantInstance.tags?.size()}">, </g:if>
							</g:each>
							</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="avgPrice" default="Average price" /></td>
                            <td valign="top" class="value">
                            <g:if test="${restaurantInstance.avgPrice() > 0}">
		                    	<g:formatNumber number="${restaurantInstance.avgPrice()/100}" type="currency" locale="${locale}" currencyCode="EUR" /> (${Round.countBySelection(restaurantInstance)} <g:message code="selections" default="selection(s)" />)
		                    </g:if>
		                    <g:else>
		                    	<g:message code="notAvailable" default="Not available" />
		                    </g:else>
							</td>
                        </tr>
                        
                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="heavyUser" default="Heavy user" /></td>
                            <g:set var="heavyUser" value="${restaurantInstance.heavyUser()}" />
                            <td valign="top" class="value">
                            <g:if test="${heavyUser}">
                            	<g:link controller="user" action="show" id="${heavyUser.user?.id}">${heavyUser.user}</g:link> - ${heavyUser.count} <g:message code="times" default="times" />
                            </g:if>
                            <g:else>
                            	<g:message code="noSelections" default="No selections" />
                            </g:else>
                            </td>
                        </tr>

                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="heavyVoter" default="Heavy voter" /></td>
                            <g:set var="heavyVoter" value="${restaurantInstance.heavyVoter()}" />
                            <td valign="top" class="value">
                            <g:if test="${heavyVoter}">
                            	<g:link controller="user" action="show" id="${heavyVoter.user?.id}">${heavyVoter.user}</g:link> - ${heavyVoter.sum} <g:message code="times" default="times" />
                            </g:if>
                            <g:else>
                            	<g:message code="noSelections" default="No selections" />
                            </g:else>
                            </td>
                        </tr>

                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="voteSelectionRatio" default="Vote-Selection ratio" /></td>
                            <g:set var="votesNeeded" value="${restaurantInstance.voteSelectionRatio()}" />
                            <td valign="top" class="value">
                            <g:if test="${votesNeeded}">
                            	<g:formatNumber number="${votesNeeded}" type="number" maxFractionDigits="2" roundingMode="HALF_UP" locale="${locale}" /> <g:message code="votesNeededForSelection" default="votes needed for a selection" />
                            </g:if>
                            <g:else>
                            	<g:message code="noSelections" default="No selections" />
                            </g:else>
                            </td>
                        </tr>

                        <tr class="prop">
                            <td valign="top" class="name"><g:message code="mostPopularOn" default="Most popular on" /></td>
                            <g:set var="mostPopularDayOfWeek" value="${restaurantInstance.mostPopularDayOfWeek()}" />
                            <td valign="top" class="value">
                            <g:if test="${mostPopularDayOfWeek}">
                            	<g:message code="day.${mostPopularDayOfWeek}" />s
                            </g:if>
                            <g:else>
                            	<g:message code="noSelections" default="No selections" />
                            </g:else>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <br />
            
        </div>
    </body>
</html>